<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billId">
              <a-input :disabled=formDisabled v-model="model.billId" placeholder="请输入单据编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="采购大类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bigCategory">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.bigCategory" dictCode="" placeholder="请选择采购大类" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="采购小类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="smallCategory">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.smallCategory" dictCode="" placeholder="请选择采购小类" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发票类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isSpecial">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.isSpecial" dictCode="invoice_type" placeholder="请选择发票类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="费用所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
              <a-input :disabled=formDisabled v-model="model.teamId" placeholder="请输入费用所属团队"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报销金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.amount" placeholder="请输入报销金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="税费金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxation">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.taxation" placeholder="请输入税费金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="未税金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="untaxedAmount">
              <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.untaxedAmount" placeholder="请输入未税金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联采购合同" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relContractId">
              <a-input :disabled=formDisabled v-model="model.relContractId" placeholder="请输入关联采购合同"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ErpFinanceReimbursementPurchaseyFeeInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        bigCategory: [
            { required: true, message: '请输入采购大类!'},
        ],
        smallCategory: [
            { required: true, message: '请输入采购小类!'},
        ],
        amount: [
            { required: true, message: '请输入报销金额!'},
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
        ],
        taxation: [
            { required: false},
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
        ],
        untaxedAmount: [
            { required: false},
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
        ],
        },
        url: {
          add: "/api/erp/finance/reimbursement/erpFinanceReimbursementPurchaseyFeeInfo/add",
          edit: "/api/erp/finance/reimbursement/erpFinanceReimbursementPurchaseyFeeInfo/edit",
          queryById: "/api/erp/finance/reimbursement/erpFinanceReimbursementPurchaseyFeeInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
